'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数 
	// console.log('event : ', event)
	const db = uniCloud.database();
	const dbCmd = db.command;
	const action = event.action;
	let dbRes;
	if(action == "get"){
		dbRes = await db.collection("goods").where({
			goods_id:dbCmd.eq(event.goods_id)
		}).get()
	}else if(action == "query"){
		dbRes = await db.collection('goods').where({
			goods_name: new RegExp(event.goods_name, 'i')
		}).get()
	}else if(action == "cate"){
		dbRes = await db.collection('goods').where({
			goods_cat: dbCmd.eq(event.cat_id)
		}).get()
	}
	//返回数据给客户端 
	return dbRes?dbRes.data:null;
};
